<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <span id="span0"></span>
  <script src="../../js/ultis.js"></script>
  <script>
    //需求：求一个倒计时
    setInterval(function () {
      var time1 = new Date(); //当前时间
      var time2 = new Date("2020-08-20 20:33:10") //输入的时间
      span0.innerHTML = timeDifference(time1, time2)
    }, 1000)

    function timeDifference(date1, date2) {
      var time1 = date1.getTime(); //得到是 date1到格林威治时间的毫秒数
      var time2 = date2.getTime(); //得到是 date2到格林威治时间的毫秒数

      let times = Math.abs(time2 - time1); //求得两个时间的总毫秒数
      let day = parseInt(times / 1000 / 60 / 60 / 24);
      let h = parseInt((times / 1000 / 60 / 60) % 24)
      h = h < 10 ? +"0" + h : h
      let m = parseInt((times / 1000 / 60) % 60)
      m = m < 10 ? "0" + m : m
      let s = parseInt((times / 1000) % 60)
      s = s < 10 ? "0" + s : s
      return "2020-08-20 20:33:10距离此时间还有：" + day + "天" + h + "小时" + m + "分钟" + s + "秒"
    }
  </script>
</body>

</html>